package com.ccb.jyzx.expand.ouapi.controller;

import com.ccb.jyzx.expand.ouapi.beans.UserInfo;
import com.ccb.jyzx.expand.ouapi.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import com.ccb.jyzx.expand.ouapi.view.request.DepIdRequest;
import com.ccb.jyzx.expand.ouapi.view.request.IdRequest;
import com.ccb.jyzx.expand.ouapi.view.request.OrgIdRequest;
import com.ccb.jyzx.expand.ouapi.view.request.UserNameRequest;

import java.util.ArrayList;
import java.util.List;

/**
 * @author XIEFEI
 * @date 2019-11-11 14:37
 * @Description 用户信息接口
 **/
@Controller
@RequestMapping("/ooapi/api/user")
@Api(tags = "用户信息相关接口")
public class UserInfoController {

    @Autowired
    UserInfoService userInfoService;

    @ApiOperation(value = "根据登陆账户查询用户信息", notes = "根据登陆账户查询用户信息")
    @ResponseBody
    @PostMapping(value = "getById",consumes = "application/json;charset=UTF-8")
    public UserInfo getByUserName(@RequestBody IdRequest json){
        return StringUtils.isNotBlank(json.getId())? userInfoService.getById(json.getId()):new UserInfo();
    }

    @ApiOperation(value = "根据登陆账户查询用户信息", notes = "根据登陆账户查询用户信息")
    @ResponseBody
    @PostMapping(value = "getByUserName",consumes = "application/json;charset=UTF-8")
    public UserInfo getByUserName(@RequestBody UserNameRequest json){
        return StringUtils.isNotBlank(json.getUserName())? userInfoService.getByUserName(json.getUserName()):new UserInfo();
    }

    @ApiOperation(value = "根据部门Id查询用户信息", notes = "根据部门Id查询用户信息")
    @ResponseBody
    @PostMapping(value = "getByDepId",consumes = "application/json;charset=UTF-8")
    public List<UserInfo> getByDepId(@RequestBody DepIdRequest json){
        return StringUtils.isNotBlank(json.getDepId())? userInfoService.getByDepId(json.getDepId()):new ArrayList<>();
    }

    @ApiOperation(value = "根据组织Id查询用户信息", notes = "根据组织Id查询用户信息")
    @ResponseBody
    @PostMapping(value = "getByOrgId",consumes = "application/json;charset=UTF-8")
    public List<UserInfo> getByOrgId(@RequestBody OrgIdRequest json){
        return StringUtils.isNotBlank(json.getOrgId())? userInfoService.getByOrgId(json.getOrgId()):new ArrayList<>();
    }


}
